#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.api.controller;

import com.github.pagehelper.PageInfo;
import ${package}.common.dto.ResultDto;
import ${package}.pojo.Demo;
import ${package}.pojo.vo.DemoInputVo;
import ${package}.pojo.vo.DemoOutputVo;
import ${package}.service.DemoService;
import ${package}.service.convert.DemoInputVoConverter;
import ${package}.service.convert.DemoOutputVoConverter;
import ${package}.service.convert.DemoPageInfoOutputVoConverter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;

/**
 * @author qingchang.tang
 * @date 2020/5/25 16:48
 */
@RestController
@RequestMapping("/demo")
@Scope("prototype")
@AllArgsConstructor
@Api(value = "demo", tags = "demo")
public class DemoController {

    private final DemoService demoService;

    @PostMapping("/save")
    @ApiOperation("save")
    public ResultDto<Long> save(@RequestBody DemoInputVo vo) {
        return ResultDto.ok(demoService.save(new DemoInputVoConverter().convert(vo)));
    }

    @GetMapping("/get")
    @ApiOperation("get")
    public ResultDto<DemoOutputVo> get(@RequestParam Long id) {
        Demo demo = demoService.get(id);
        return ResultDto.ok(new DemoOutputVoConverter().convert(demo));
    }

    @DeleteMapping("/del")
    @ApiOperation("del")
    public ResultDto<Integer> del(@RequestParam Long id) {
        return ResultDto.ok(demoService.del(id));
    }

    @GetMapping("/list")
    @ApiOperation("list")
    public ResultDto<PageInfo<DemoOutputVo>> list(@RequestParam(required = false, defaultValue = "1") int page,
                                                  @RequestParam(required = false, defaultValue = "5") int size) {
        return ResultDto.ok(new DemoPageInfoOutputVoConverter().convert(demoService.list(page, size)));
    }
}
